package T9Spelling;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class T9Spelling {

	/**
	 * @param args
	 * @throws FileNotFoundException
	 */
	public static void main(String[] args) throws FileNotFoundException {
		String file = "src/T9Spelling/C-large-practice.in";
		Scanner sc = new Scanner(new File(file));

		int numberOfsets;
		numberOfsets = sc.nextInt();
		sc.nextLine();

		int digit = 0, prevDigit=-1, keyPress = 0;

		for (int i = 1; i <= numberOfsets; i++) {
			String line = sc.nextLine();
			
			System.out.print("Case #" + i + ": ");
			for (int j = 0; j < line.length(); j++) {
				int c = line.charAt(j) - 97; // a is 97.

				if (c < 0) {
					// for spacebar
					digit=0;
					keyPress=1;
				} else if (c < 15) {
					// for a ~ o
					digit = c / 3 + 2;
					keyPress = c % 3 + 1;
				} else if (c < 19) {
					// for p ~ s
					digit = 7;
					keyPress = (c - 15) % 4 + 1;
				} else if (c < 22) {
					// for t ~ v
					digit = 8;
					keyPress = (c - 19) % 3 + 1;
				} else {
					// for w ~ z
					digit = 9;
					keyPress = (c - 22) % 4 + 1;
				}
				if (j > 0 && prevDigit == digit) {
					// for spacing
					System.out.print(" ");
				}
				for (int k = 0; k < keyPress; k++) {
					System.out.print(digit);
				}
				prevDigit=digit;
			}
			System.out.println();
		}
		sc.close();
	}
}
